﻿using System;
using System.Drawing;

namespace HMaker.Controls
{
    /// <summary>
    /// 一个用于表示坐标原点的对象,
    /// </summary>
    public class OriginPos
    {
        private Point _Location;

        /// <summary>
        /// 坐标原点的位置
        /// </summary>
        public Point Location
        {
            get => _Location; set
            {
                if (!Equals(_Location, value))
                {
                    _Location = value;
                    LocationChanged?.Invoke(this, EventArgs.Empty);
                }
            }
        }

        /// <summary>
        /// 当坐标原点发生改变时,通知其他绑定到此对象的图形更新位置
        /// </summary>
        public event EventHandler LocationChanged;

        /// <summary>
        /// 计算此坐标原点,到某个绝对坐标(相对于容器)的偏移
        /// </summary>
        /// <returns></returns>
        public Point CalcOffset(Point targetPoint)
        {
            return new Point(targetPoint.X - Location.X, targetPoint.Y - Location.Y);
        }

        /// <summary>
        /// 通过偏移量直接计算某个偏移量相对的绝对坐标(相对于容器)
        /// </summary>
        /// <param name="targetOffset"></param>
        /// <returns></returns>
        public Point CalcLocation(Point targetOffset)
        {
            targetOffset.Offset(Location);
            return targetOffset;
        }
    }
}
